﻿using System; 
using System.Collections.Generic; 
using System.ComponentModel; 

namespace DataAccess{
[Serializable]
[GenWiseAttribute(IsDataSourceEntity = true) ]
public class lastWeekVisit : INotifyPropertyChanged
 {


#region --- Class Fields / Objects  ---

[NonSerialized]
protected PropertyChangedEventHandler _propertyChanged;
private System.Int32 _id;
private System.Int32? _art_id;
private System.Int32? _visits;
private art _art;

#endregion


#region --- Class Properties ---

public virtual System.Int32 id 
{
get
{
return _id;
}
}

public virtual System.Int32? art_id 
{
get
{
if ( art != null ) 
{
_art_id = (System.Int32)art.id;
}

return _art_id;
}
set 
{
if ( _art_id != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_art = null;

_art_id = value ;
OnPropertyChanged("art_id");
}
}
}

public virtual System.Int32? visits 
{
get
{
return _visits;
}
set 
{
if ( _visits != value) 
{
_visits = value ;
OnPropertyChanged("visits");
}
}
}

/// <summary>
/// Generated from Relation FK_LastWeekVisits_Art
/// </summary>
[GenWiseAttribute(RelationID = "c26638fb-b2e2-4108-a85c-ada5340b01bf") ]
public virtual art art 
{
get
{
if ( _art == null ) 
{
if ( !_art_id.HasValue || _art_id.Value.Equals(System.Int32.MinValue) ) 
{
if ( _art != null && ( _art.id.Equals(null) ) )
{
  _art = null;
}
}
else
{
_art = (new artFactory()).Get(_art_id.Value);
}
}

return _art;
}
set 
{
if ( _art != value) 
{
if ( value==null ) _art_id = null; else _art_id = (System.Int32)value.id; 
_art = value ;
}
}
}

/// <summary>
/// Is this object Valid? 
/// </summary>
/// <remarks>
/// This is achieved by counting how many errors are returned from the Validate() method. If no errors are found then it's valid.
/// </remarks>
[Bindable(false)]
public virtual System.Boolean IsValid 
{
get
{
List<Error> _errors = this.Validate(); if ( _errors.Count > 0 ) return false; else return true;
}
}


#endregion


#region --- Class Methods --- 

/// <summary>
/// Raises PropertyChanged event.
/// </summary>
protected virtual void OnPropertyChanged(System.String ppropertyChanged)
{
if (_propertyChanged != null) _propertyChanged( this , new PropertyChangedEventArgs(ppropertyChanged));

}

/// <summary>
/// Create a new lastWeekVisit object. 
/// </summary>
public  lastWeekVisit()
{
_id = System.Int32.MinValue;

}

/// <summary>
/// Validates the object returning a list of errors if the validation fails.
/// </summary>
/// <remarks>
/// You can use the provided User CodeBlocks to add your own validations.
/// </remarks>
///<returns>Returns the List of Errors found during the Validation. If no errors are found null is returned.<returns>
public virtual List<Error> Validate()
{
List<Error> _errors = new List<Error>();
return _errors;
}


#endregion


#region --- Class Events  ---

public event PropertyChangedEventHandler PropertyChanged 
{
   add {
_propertyChanged+= value;
   }
   remove {
_propertyChanged-= value;
   }
}


#endregion
}
}

